package com.xt.base.dao.hibernate.system;

import java.util.List;

import com.xt.base.dao.hibernate.BaseDaoHibernate;
import com.xt.base.dao.hibernate.SessionFactoryHolder;
import com.xt.base.model.base.Organization;
import com.xt.base.model.dictionary.DesktopItem;
import com.xt.base.model.dictionary.Function;
import com.xt.base.model.dictionary.FunctionGroup;
import com.xt.base.model.system.Role;
import com.xt.base.model.system.User;

public class SystemDaoTool extends BaseDaoHibernate {
	private static final long serialVersionUID = -8846509360831318062L;
	private static SystemDaoTool instance;



	@SuppressWarnings("unchecked")
	public List<Role> getRolesByUserCode(
			String userCode) {
		return getSession().getNamedQuery("getRolesByUserCode")
				.setString("userCode", userCode).list();
	}

	@SuppressWarnings("unchecked")
	public List<Function> getFunctionsByUserCode(
			String userCode) {
		return getSession().getNamedQuery("getFunctionsByUserCode")
				.setString("userCode", userCode).list();
	}

	@SuppressWarnings("unchecked")
	public List<DesktopItem> getDesktopItemsByUserCode(
			String userCode) {
		return getSession().getNamedQuery("getDesktopItemsByUserCode")
				.setString("userCode", userCode).list();
	}

	@SuppressWarnings("unchecked")
	public List<FunctionGroup> getFunctionGroupssByUserCode(
			String userCode) {
		return getSession().getNamedQuery("getFunctionGroupssByUserCode")
				.setString("userCode", userCode).list();
	}

	@SuppressWarnings("unchecked")
	public List<Role> getRolesByUserCodeAndAppCode(
			String userCode,String appCode) {
		return getSession().getNamedQuery("getRolesByUserCodeAndAppCode")
				.setString("userCode", userCode).setString("appCode", appCode).list();
	}


	public Organization getSuperOrganizatiosByCode(String code) {
		return (Organization)getSession().getNamedQuery("getSuperOrganizatiosByCode").setString("code", code).uniqueResult();
	}
	
	private SystemDaoTool() {
		super.setSessionFactory(SessionFactoryHolder.getInstance()
				.getSessionFactory());
	}

	synchronized static public  SystemDaoTool getInstance() {
		if (instance == null)
			instance = new SystemDaoTool();
		return instance;
	}

	@SuppressWarnings("unchecked")
	protected Class getEntityClass() {
		return User.class;
	}

}
